package cluster

import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.cluster.client.ClusterClientReceptionist
import com.typesafe.config.ConfigFactory
import spark.woker.SparkWoker
import spark.woker.SparkWoker.{clientHost, clientPort, config, contextName, serverHost, serverName, serverPort}

/**
 * Created by DJJ on 2019/12/13.
 */
class Cluster1 extends Actor{

  override def receive: Receive = {
    case "start" =>println("Cluster1 hello ")
    case "master"=>
      println("-------------Cluster1_________")
      println(sender())
    case ClusterMessage(path)=>
      println("收到集群客户端的消息----Cluster1")
      val unit = context.actorSelection(path)
      unit ! "hello"
  }
}
object  Cluster1 extends App{


  val config = ConfigFactory.parseString(
    s"""
       |akka.remote.netty.tcp.hostname="127.0.0.1"
       |akka.remote.netty.tcp.port=9990
        """.stripMargin).withFallback(ConfigFactory.load())
  val sparkWoker = ActorSystem("Cluster", config)
  val requestLimiter:ActorRef={
    sparkWoker.actorOf(Props[Cluster1],"Cluster")
  }
  ClusterClientReceptionist(sparkWoker).registerService(requestLimiter)

}

